package com.czy.form.model;

import lombok.Data;

import javax.persistence.*;
import java.util.Set;

/***
 * @ ClassName: FormField
 * @ Description: TODO
 * @ author：libi
 * @ date： 2020/2/1 13:14
 * @ version： V1.0.0
 * @ CopyRight：czy
 */

@Entity
@Table(name = "form_field_info", schema = "form")
@Data
public class FormFieldInfo extends FormMeta{

    @Column(name = "form_id", columnDefinition = "varchar(36) comment 'form外键'")
    String formId;

    @Enumerated(EnumType.STRING)
    @Column(name = "type")
    FieldType type;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "field_id")
    Set<FormFieldOption> options;

    @Column(name = "required", columnDefinition = "bit(1) comment '是否必填'")
    Boolean required;

    @Column(name = "validator", columnDefinition = "varchar(100) comment '自定义校验器'")
    String validator;

    @Override
    public boolean equals(Object obj){

        if(obj instanceof FormFieldInfo){
            FormFieldInfo target = (FormFieldInfo) obj;
            if(this.id == null || target.getId() == null){
                return false;
            }else if(this.id.equals(target.getId())){
                return true;
            }
        }

        return false;
    }
}
